package monkeyXML;

import java.io.Reader;

public class XMLHeader extends XMLNode
{
   private String theHeader;
   
   public XMLHeader( Reader aReader ) throws Exception
   {
      char current = (char)aReader.read();
      
      //read off whitespace
      while( current == '\n' || current == ' ' || current == '\r' )
      {
         current = (char) aReader.read();
      }
      
      if( current == '<' )
      {
         StringBuffer value = new StringBuffer();
         
         value.append( current );
         current = (char)aReader.read();
         if( current != '?' )
         {
            throw new Exception( "Parse Error: No header\n" );
         }
         
         while( current != '>' )
         {
            value.append( current );
            current = (char)aReader.read();
         }
         value.append( current );
         theHeader = new String( value.toString() );
      }
      else
      {
         throw new Exception( "Error parsing XML Header" );
      }
   }

   @Override
   public String toString()
   {
      return theHeader;
   }

   @Override
   public String getTag()
   {
      return theHeader;
   }
}
